/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div class="item-title">
      <div class="subject">
        <h3>统计报表 - 会员排行</h3>
        <h5>网站系统会员排行</h5>
      </div>
    </div>
    <div
      id="explanation"
      class="explanation"
      style="color: rgb(85, 85, 85); background-color: rgb(243, 244, 244); width: 98%; height: 100%;"
    >
      <div class="bckopa-tips">
        <div class="title">
          <img src="@/static/images/handd.png" alt />
          <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
        </div>
        <ul>
          <li>统计分析会员贡献订单数量和消费金额</li>
        </ul>
      </div>
      <span title="收起提示" id="explanationZoom" style="display: block;"></span>
    </div>
    <div class="mDiv">
      <div class="ftitle">
        <h3>会员排行榜</h3>
        <h5>(共 {{totalCount}} 条记录)</h5>
      </div>
      <a href @click.prevent="refresh()" class="refresh-date">
        <div title="刷新数据" class="pReload">
          <i class="fa fa-refresh"></i>
        </div>
      </a>
      <div class="searchbox">
        <el-date-picker
          size="small"
          v-model="dateRange"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="起始日期"
          end-placeholder="截止日期"
        ></el-date-picker>
        <el-input
          class="searchinput"
          v-model="mobile"
          width="10"
          size="small"
          placeholder="手机号码"
          clearable
        />
        <el-input
          class="searchinput"
          v-model="email"
          width="10"
          size="small"
          placeholder="email"
          clearable
        />
        <el-button
          class="searchbtn"
          size="small"
          icon="el-icon-search"
          @click="currentPage = 1;getPage()"
        >搜索</el-button>
      </div>
    </div>
    <div class="tablebox" v-if="tableData">
      <el-table :data="tableData" ref="multipleTable" style="width: 100%;">
        <el-table-column label="ID" prop="user_id" width="90"></el-table-column>
        <el-table-column label="排行" type="index" :index="indexMethod" width="100"></el-table-column>
        <el-table-column label="会员名称" prop="username" width="150" show-overflow-tooltip></el-table-column>
        <el-table-column label="会员手机" prop="mobile" width="180"></el-table-column>
        <el-table-column label="会员邮箱" prop="email" width="200"></el-table-column>
        <el-table-column label="订单数" prop="order_num" width="100"></el-table-column>
        <el-table-column label="购物金额" prop="amount" width="100"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button-group>
              <el-button size="small" @click="detail(scope.row.user_id)" icon="el-icon-zoom-in">查看</el-button>
            </el-button-group>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        class="paginationbox"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { getUserTop } from "@/utils/api";
export default {
  data() {
    return {
      tableData: [],
      currentPage: this.$route.params.currentPage || 1,
      totalCount: 0,
      pageSize: 20,
      dateRange: [
        new Date(new Date().toLocaleDateString()).getTime() -
          6 * 60 * 60 * 24 * 1000,
        new Date(new Date().toLocaleDateString()).getTime() +
          (1 * 60 * 60 * 24 * 1000 - 1000)
      ],
      query: {},
      mobile: null,
      email: null
    };
  },
  created() {
    this.getPage();
  },
  methods: {
    handleSizeChange(e) {
      this.pageSize = e;
      this.getPage();
    },
    handleCurrentChange(e) {
      this.currentPage = e;
      this.getPage();
    },
    getPage() {
      var that = this;
      this.query.p = this.currentPage;
      this.query.size = this.pageSize;
      this.query.mobile = this.mobile;
      this.query.email = this.email;
      if (this.dateRange) {
        this.query.start_time = parseInt(this.dateRange[0].valueOf() / 1000);
        this.query.end_time = parseInt(this.dateRange[1].valueOf() / 1000);
      } else {
        this.query.start_time = null;
        this.query.end_time = null;
      }
      getUserTop(that.query).then(function(res) {
        that.tableData = res.records;
        that.totalCount = res.total;
      });
    },
    refresh() {
      this.currentPage = 1;
      this.getPage();
      this.$message.success("刷新成功！");
    },
    detail(id) {
      this.$router.push({
        name: "orders",
        params: {
          user_id: id
        }
      });
    },
    indexMethod(index) {
      let curpage = this.currentPage; //单前页码
      let limitpage = this.pageSize; //每页条数
      return index + 1 + (curpage - 1) * limitpage;
    }
  }
};
</script>

<style scoped>
.searchinput {
  width: auto;
}
</style>
